package pl.edu.agh.neuraleconomy.ui.component;

import java.util.Date;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

import pl.edu.agh.neuraleconomy.ui.util.UIUtils;

public class PredictionPanel extends Composite {

	private Button predictionButton;
	private DateTime dateFrom;
	private Text sessionsText;

	public PredictionPanel(Composite arg0, int arg1) {
		super(arg0, arg1);
		init();
	}

	private void init() {
		this.setLayout(new GridLayout(1, false));

		Group predictionGroup = new Group(this, SWT.SHADOW_IN);
		predictionGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
		predictionGroup.setText("Prediction");
		predictionGroup.setLayout(new GridLayout(2, false));

		predictionButton = new Button(predictionGroup, SWT.CHECK);
		predictionButton.setText("Predict");

		GridData gridData = new GridData();
		gridData.horizontalAlignment = SWT.FILL;
		gridData.horizontalSpan = 2;

		predictionButton.setLayoutData(gridData);

		((new Label(predictionGroup, SWT.NONE))).setText("From");
		dateFrom = new DateTime(predictionGroup, SWT.DATE | SWT.DROP_DOWN);

		((new Label(predictionGroup, SWT.NONE))).setText("Sessions");
		sessionsText = new Text(predictionGroup, SWT.BORDER);
		sessionsText.setText("5");

		gridData = new GridData();
		gridData.horizontalAlignment = SWT.FILL;
		sessionsText.setLayoutData(gridData);
	}

	public boolean getPredict() {
		return predictionButton.getSelection();
	}

	public void setPredict(boolean value) {
		predictionButton.setSelection(value);
	}

	public Date getDate() {
		return UIUtils.getDateFromDateTimeWidget(dateFrom);
	}

	public void setDate(Date date) {
		UIUtils.setDateInDateTimeWidget(dateFrom, date);
	}

	public int getSessions() {
		try {
			return Integer.valueOf(sessionsText.getText());
		} catch (Exception e) {
			return 0;
		}
	}
	
	public void setSessions(int sessions){
		this.sessionsText.setText(String.valueOf(sessions));
	}
}
